/**
 * Created by huangchuang on 2017/8/31 0031.
 */
import {getwxFansList, getwxFansTagList, addWxTag, addTagToUser, addToBlack, syncUpdateFans, triggerUpdateFans, delWxTag} from '@/service/getData'
import * as type from '@/store/mutation-types'
const state = {
  fansList: { // 粉丝列表
    list: [],
    page: {}
  },
  tagsList: []
}
const actions = {
  /* 获取粉丝列表 */
  async getFansList ({commit, state}, payload) {
    let res = await getwxFansList(payload)
    commit(type.GET_FANSLIST, res.data.data)
  },
  /* 获取标签列表 */
  async getwxTagList ({commit, state}, appid) {
    let res = await getwxFansTagList(appid)
    if (res.data.data) {
      commit(type.SET_WXTAGLIST, res.data.data.tags)
    }
    return res
  },
  /* 添加标签 */
  async addwxTag ({commit, state}, payload) {
    let res = await addWxTag(payload)
    commit(type.ADD_WXTAG, res.data.data)
    return res
  },
  async delWxTag ({commit, state}, payload) {
    let res = await delWxTag(payload)
    return res
  },
  /* 给用户添加标签 */
  async addwxTagToUser ({commit, state}, payload) {
    let res = await addTagToUser(payload)
    return res
  },
  /* 拉黑粉丝 */
  async addwxToBlack ({commit, state}, payload) {
    let res = await addToBlack(payload)
    return res
  },
  /* 触发同步更新粉丝 */
  async triggerUpdateFan ({commit, state}, payload) {
    let res = await triggerUpdateFans(payload)
    return res
  },
  /* 同步更新粉丝进度 */
  async asyncUpdateFans ({commit, state}, payload) {
    let res = await syncUpdateFans(payload)
    return res
  }
}
const mutations = {
  [type.GET_FANSLIST] (state, payload) {
    state.fansList = payload
  },
  [type.SET_WXTAGLIST] (state, payload) {
    if (payload) {
      state.tagsList = payload
    } else {
      state.tagsList = []
    }
  },
  [type.ADD_WXTAG] (state, payload) {
    // state.tagsList = state.tagsList.concat([payload])
    state.tagsList.push(payload)
  }
}

export default {
  state,
  actions,
  mutations
}
